Skip to content

Add differential property tests - #47

Merged
michaelsproul merged 4 commits into
sigp:mainfrom
eserilev:add-proptest
Jul 27, 2026
Merged

Add differential property tests#47
michaelsproul merged 4 commits into
sigp:mainfrom
eserilev:add-proptest

Conversation

@eserilev

@eserilev eserilev commented Jul 22, 2026

Copy link
Copy Markdown
Member

Add differential property testing in CI to test agreement across our three merkelize implementations. Previously we were only testing a handful of cases. Now we are testing against 300k randomly generated inputs.

Also two minor bugfixes:

  • MerkleHasher depth defintion is inconsistent and our depth guard is incorrect and silently truncates leaves. The bug doesn't seem reachable as long as the library is used correctly.
  • random_bytes was using Vec::with_capacity(bytes) which creates a zero length vec. So fill_bytes filled nothing, all existing random test were testing empty input.

PR written by Claude, but self reviewed by me

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.46%. Comparing base (dbf20c3) to head (383f88f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #47      +/-   ##
==========================================
+ Coverage   87.75%   90.46%   +2.70%     
==========================================
  Files           6        7       +1     
  Lines         294      409     +115     
==========================================
+ Hits          258      370     +112     
- Misses         36       39       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +133 to 134
/// has a depth of 1, and a tree with 4 leaves has a depth of 3.
depth: usize,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change this to be depth = 0 at the root node instead of depth = 1 OR we could change this field name to num_layers

Or we can just keep as is, with an updated comment. I dont have a super strong opinion either way, though I think changing the value of depth might technically be a sketchier change

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can come back for some cleanup here, I've opened an issue:

@michaelsproul michaelsproul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, great catch!

@michaelsproul
michaelsproul merged commit 6cbb79e into sigp:main Jul 27, 2026
8 checks passed
eserilev added a commit to eserilev/tree_hash that referenced this pull request Jul 28, 2026
Extend the differential property tests (sigp#47) and derive macro tests (sigp#48)
to cover the new functionality in the progressive branch:

- Property test ProgressiveMerkleHasher against a recursive reference
  implementation of EIP-7916 merkleize_progressive, with random byte
  lengths and random write splits to exercise the partial-chunk carry
  buffer, up to 128 chunks to cross all early level boundaries.
- Property test ProgressiveBitList hashing against the same reference
  with independent bit packing, covering the empty-list workaround.
- Derive tests for progressive containers: skip_hashing interaction,
  nesting (both directions), generics, tree_hash_type, a six-field
  container crossing a progressive level boundary, and active_fields
  spanning multiple bytes.
- Hard-coded roots for the level-crossing and multi-byte cases computed
  independently from the EIP pseudocode, so these tests do not rely on
  the hasher under test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017PpXigbebk4GAQ9D9qdFzU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants